public class Test {
    private static int sum1=0;
    private static int sum2=0;
    public static void main(String[] args) throws InterruptedException {
        long beg=System.currentTimeMillis();
        int[] arr=new int[1000];
        for (int i = 0; i < 1000; i++) {
            arr[i]=1;
        }
        Thread t1=new Thread(()->{
            for (int i = 0; i < 1000; i+=2) {
                sum1+=arr[i];
            }
        });

        Thread t2=new Thread(()->{
            for (int i = 1; i < 1000; i+=2) {
                sum2+=arr[i];
            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();

        long end=System.currentTimeMillis();

        System.out.println(sum1+sum2);
        System.out.println("运行时间："+(end-beg));
    }
}
